package com.sky.mapper;

import com.sky.annotation.AutoFill;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.entity.DishFlavor;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface DishMapper {

    /**
     * 根据分类id查询菜品数量
     * @param categoryId
     * @return
     */
    @Select("select count(id) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);

    //新增菜品
    @AutoFill(value = OperationType.INSERT)
    void addDish(Dish dish);

    //分页查询菜品
    List<DishVO> selDishAll(DishPageQueryDTO dishPageQueryDTO);

    //通过id查询菜品
    @Select("select id, name, category_id, price, image, description, status, create_time, update_time, create_user, update_user " +
            "from dish where id = #{id};")
    DishVO selDishById(Long id);


    //根据分类id查询菜品
    @Select("select id, name, category_id, price, image, description, status, create_time, update_time, create_user, update_user from dish where category_id = #{categoryId};")
    List<Dish> selDishByCategoryId(Long categoryId);

    //修改菜品
    @AutoFill(OperationType.UPDATE)
    void updateTimeDish(Dish dish);

    //修改菜品的口味
    void updateTimeDishFlavor(DishFlavor dishFlavor);

    //批量删除菜品
    void delDishById(List<Long> idLis);

    /**
     * 根据条件统计菜品数量
     * @param map
     * @return
     */
    Integer countByMap(Map map);
}
